package org.de.maeyer.statistic;

import static org.de.maeyer.unit.UnitUtils.*;

import org.de.maeyer.unit.Unit;
import org.de.maeyer.util.Clock;

/**
 * @author Peter De Maeyer
 */
public class ElapsedTimeAccumulator implements Accumulator {

	private final Clock clock;
	
	private final Unit timeUnit;

	private long offsetTime;

	public ElapsedTimeAccumulator(Clock clock) {
		this(clock, clock.getTime());
	}

	public ElapsedTimeAccumulator(Clock clock, long offsetTime) {
		this.clock = clock;
		this.offsetTime = offsetTime;
		timeUnit = unitFromTimeUnit(clock.getTimeUnit());
	}

	/**
	 * Resets the offset time to the current time.
	 */
	@Override
	public void reset() {
		offsetTime = clock.getTime();
	}
	
	@Override
	public void accumulate() {
	}
	
	@Override
	public void accumulateObject(Object value) {
	}
	
	@Override
	public void accumulateDouble(double value) {
	}
	
	@Override
	public void accumulateLong(long value) {
	}
	
	@Override
	public void appendTo(StatisticsBuilder builder) {
	    builder.setElapsedTime(clock.getTime() - offsetTime, timeUnit);
	}
}
